#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
  int **tab;
} plateau ;

void creaPlateau(plateau *p){
  int i,j,taille;
  for(i=0;i<9;i++){
    taille=tailleLigne(i);
    for(j=0;j<taille;j++){
      if(i<2 || (i==2 && (j>1 && j<5)))
	p->tab[i][j]='B';
      else if(i>6 || (i==6 && (j>1 && j<5)))
	p->tab[i][j]='N';
      else 
	p->tab[i][j]=0;
    }
  }
}

int tailleLigne(int ligne){
  switch(ligne){
  case 0:
    return 5;
    break;
  case 8:
    return 5;
    break;
  case 1:
    return 6;
    break;
  case 7:
    return 6;
    break;
  case 2:
    return 7;
    break;
  case 6:
    return 7;
    break;
  case 3:
    return 8;
    break;
  case 5:
    return 8;
    break;
  case 4:
    return 9;
    break;
  default:
    return 0;
  }
}

char *toString(plateau *p){
  char *tab=malloc(100*sizeof(int));
  int i,j;
  char *lettre="";
  char *chiffre="9";
  int taille;
  strcat(tab,"       -----------    \n");
  for (i=8;i>=0;i--){
    *lettre=(65+i);
    printf("%d,%s\n",i, lettre);
    taille=tailleLigne(i);
    for(j=i-taille+1;j>=0;j--)
      strcat(tab," ");
    strcat(tab,lettre);
    if(i>4)
      strcat(tab,"/");
    else if(i==4)
      strcat(tab,"  ");
    else
      strcat(tab,"\\");
    for (j=taille;j>=0;j--){
      strcat(tab," ");
      if(*(*(p->tab+i)+j)=='N')
	strcat(tab,"N");
      else if(*(*(p->tab+i)+j)=='B')
	strcat(tab,"B");
      else
	strcat(tab,"*");
    }
    if(i>4)
      strcat(tab,"\\");
    else if(i<4)
      strcat(tab," /");
    strcat(tab,chiffre--);
    strcat(tab,"\n");
    //    printf("i : %d \n %s",i,tab);
  }
  strcat(tab,"       ----------  6\n          1 2 3 4 5 \n");
  return tab;
  }
  
int main(){
  plateau *p=malloc(sizeof(int*));;
  p->tab=malloc(9*sizeof(int*));
  int i,j;
  for(i=0;i<9;i++)
    p->tab[i]=malloc(tailleLigne(i)*sizeof(int));
  //  printf("%d\n",*(*p->tab));
  creaPlateau(p);
  /*for(i=0;i<9;i++){
    printf("%d",i);
    for(j=0;j<tailleLigne(i);j++){
      printf(" %c",p->tab[i][j]);
    }
    printf("\n");
    }*/
  printf("%s\n",toString(p));
  return 0;
}
